package com.mall.product.service.impl;

import com.mall.common.es.SkuEsModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.utils.PageUtils;
import com.mall.common.utils.Query;

import com.mall.product.dao.ProductAttrValueDao;
import com.mall.product.entity.ProductAttrValueEntity;
import com.mall.product.service.ProductAttrValueService;


@Service("productAttrValueService")
public class ProductAttrValueServiceImpl extends ServiceImpl<ProductAttrValueDao, ProductAttrValueEntity> implements ProductAttrValueService {

    @Autowired
    private ProductAttrValueDao productAttrValueDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProductAttrValueEntity> page = this.page(
                new Query<ProductAttrValueEntity>().getPage(params),
                new QueryWrapper<ProductAttrValueEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SkuEsModel.Attr> queryAttrInfoBySpuId(Long spuId) {
        List<ProductAttrValueEntity>  productAttrValueEntityList = productAttrValueDao.queryAttrInfoBySpuId(spuId);
       List<SkuEsModel.Attr> attrList = productAttrValueEntityList.stream().map(item->{
            SkuEsModel.Attr attr = new SkuEsModel.Attr();
           BeanUtils.copyProperties(item,attr);
            return attr;
        }).collect(Collectors.toList());
        return attrList;
    }

}